import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Test;

/**
 * 文 件 名 称：test.
 * 文 件 说 明：
 * 创   建   人：zpen.
 * 创 建 时 间：2018/9/12 16:26.
 */
public class test {

    /** 连接网站，模拟浏览器登陆，避免网站识别为手机进入 */
    private  final String USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0";

    /** 设置超时时间 */
    private  final int timeout = 50000;

    @Test
    public  void sss() {
        try {
            String url = "http://www.jsyst.cn/wxp/ks/";
            Document doc = Jsoup.connect(url).userAgent(USERAGENT).timeout(timeout).get();
            for(int a =0;a<10;a++) {
                int beg = doc.toString().indexOf("list1[" + a + "]");
                int end = doc.toString().indexOf(";", beg);
                String[] strings = doc.toString().substring(beg + 21, end - 1).split("','");
                /*选项*/
                String s = "";
                if (strings.length > 11) {
                    if (strings[5] != null && !"".equals(strings[5])) {
                        s = "A:" + strings[3] + ";B:" + strings[4];
                        s += ";C:" + strings[5];
                    } else {
                        s = strings[3] + ";" + strings[4];
                    }
                    if (strings[6] != null && !"".equals(strings[6])) {
                        s += ";D:" + strings[6];
                    }
                /*答案*/
                    String answera = "";
                    if (strings[5] != null && !"".equals(strings[5])) {
                        switch (strings[7]) {
                            case "1":
                                answera = "A";
                                break;
                            case "2":
                                answera = "B";
                                break;
                            case "3":
                                answera = "C";
                                break;
                            case "4":
                                answera = "D";
                                break;
                        }
                    } else {
                        if ("1".equals(strings[7])) {
                            answera = "正确";
                        } else {
                            answera = "错误";
                        }
                    }
                    System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                    System.out.println("问题：" + strings[2]);
                    System.out.println("选项：" + s);
                    System.out.println("答案：" + answera);
                    System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
